package com.amit.struts;

import javax.servlet.http.HttpServletRequest;


import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;

public class EnquiryIdForm extends ActionForm {
	
	private String enquiryId;

	public String getEnquiryId() {
		return enquiryId;
	}

	public void setEnquiryId(String enquiryId) {
		this.enquiryId = enquiryId;
	}
	
	@Override
	public void reset(ActionMapping mapping, HttpServletRequest request)
	{
		this.enquiryId=null;
		
	}
	
	@Override
	public ActionErrors validate(ActionMapping mapping,
			HttpServletRequest request) {
		
		ActionErrors errors=new ActionErrors();
		
		if(enquiryId==null||enquiryId.length()==0)
		{
			errors.add("enquiryId", new ActionError("error.enquiryId.required"));
		}
		else if(!enquiryId.startsWith("E-"))
		{
				errors.add("enquiryId", new ActionError("error.enquiryId.formate1"));
		}
		else
		{
			String p2=enquiryId.substring(2);
			System.out.println(p2);
			try
			{
				int x=Integer.parseInt(p2);
				System.out.println(x);
				if(x<1001)
				{
					errors.add("enquiryId", new ActionError("error.enquiryId.formate2"));
				}
			}
			catch (Exception e) {
				errors.add("enquiryId", new ActionError("error.enquiryId.formate3"));
			}
		}
		
		
		return errors;
		
		
		
	}

}
